from public.action import *
from public.tools import *
from public.testData import *
testCase = "DBshop024_删除客户评价"
# 1.登录前台界面，点击我的订单，已完成订单，点击尚未评价，
firefox=getDriver()
openBrowser(firefox,url)
login(firefox,name,password)
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_partial_link_text("交易完成").click()
firefox.find_element_by_xpath("(//a[contains(.,'尚未评价')])[1]").click()
# 编写商品评价“下次还是会回购”，点击“点击提交”按钮。
firefox.find_element_by_id("comment_body").send_keys(shoppingjia)
firefox.find_element_by_xpath("//button").click()
time.sleep(2)
print("前台评价完成")
firefox.quit()

# 2.回到后台界面，点击“编辑查看”，点击“删除”，确认删除，删除成功。
firefox=getDriver()
openBrowser(firefox,urlAdmin)
logInAdmin(firefox)
adminMenu2(firefox,"商品管理","商品评价")
firefox.find_element_by_xpath("(//a[text()='编辑查看'])[1]").click()
firefox.find_element_by_xpath("(//a[text()='删除'])[1]").click()
time.sleep(1)
firefox.switch_to.alert.accept()
time.sleep(3)

#断言
try:
    firefox.find_element_by_xpath\
        ("//td[contains(.,'%s')]/following-sibling::td[4]/a[2]"%shoppingjia).click()
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
except:
    writeLog("%s 测试通过" % testCase)
firefox.quit()

